# -*- coding: utf-8 -*-
# created on 2016/8/15

from mathsolver.functions.base import *
from mathsolver.functions.geometry.geosolver import GeoSolver


class GeoTri(BaseFunction):
    def solver(self, *args):
        geosolver = GeoSolver() if self.search("geosolver") is None else self.search("geosolver")
        self.output.append(geosolver)
        return self


class GeoUpdate(BaseFunction):
    def solver(self, *args):
        geosolver = GeoSolver() if self.search("geosolver") is None else self.search("geosolver")
        geosolver.append(args[0])
        self.output.append(geosolver)
        return self


class GeoSolve(BaseFunction):
    def solver(self, *args):
        geosolver = self.search("geosolver")
        geosolver.run(args[0])
        if isinstance(args[0], GeoExpr):
            self.steps.append(
                ["", "http://7o4zgy.com1.z0.glb.clouddn.com/question_bank/8/dc4/6d75c659936f8361d2b3b331c06ca"])
        else:
            self.steps.append(
                ["", "http://7o4zgy.com1.z0.glb.clouddn.com/question_bank/8/345/0553e65559539f4f442d18de227e9"])

        if geosolver.answer:
            self.output.append(geosolver)
            # self.steps += geosolver.steps
            # self.label.update(geosolver.label)
        else:
            raise ValueError("No answer!")

        return self


class GeoCollinear(BaseFunction):
    def solver(self, *args):
        if isinstance(args[0], BasePointnames):
            points = args[0].value
        elif isinstance(args[0], BasePointname):
            points = [args[0].value]

        line_name = "Line(%s)" % args[1].name
        geosolver = GeoSolver() if self.search("geosolver") is None else self.search("geosolver")
        for point in points:
            geosolver.append(BaseCollinear([point, line_name]))

        self.output.append(geosolver)
        return self


if __name__ == '__main__':
    pass
